package com.gscitysfy.cus.drain.modules.reserveplan.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.inspection.entity.DrainInspectionMnProblem;
import com.gscitysfy.cus.drain.modules.inspection.vo.DrainInspectionMnProblemVo;
import com.gscitysfy.cus.drain.modules.reserveplan.entity.DrainReservePlanInfo;
import com.gscitysfy.cus.drain.modules.reserveplan.service.IDrainReservePlanInfoService;
import com.gscitysfy.cus.drain.modules.reserveplan.service.impl.DrainReservePlanInfoServiceImpl;
import com.gscitysfy.cus.drain.modules.reserveplan.vo.DrainReservePlanInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shenglin
 * @since 2022-11-15 14:28:05
 */
@RestController
@RequestMapping("/reserveplan/drain-reserve-plan-info")
@Tag(name = "预案管理-基础信息表")
public class DrainReservePlanInfoController {

    @Autowired
    IDrainReservePlanInfoService drainReservePlanInfoService;

    @Resource
    private HttpServletResponse httpServletResponse;

    /**
     * 新增或修改预案基础信息
     *
     * @param drainReservePlanInfo
     * @return
     */
    @PostMapping("/saveReservePlanInfo")
    @Operation(summary = "新增或修改预案基础信息", description = "新增或修改预案基础信息")
    public Result saveReservePlanInfo(@RequestBody DrainReservePlanInfo drainReservePlanInfo) {
        if(drainReservePlanInfo!=null&&drainReservePlanInfo.getCmKid()==null){
            drainReservePlanInfo.setPublishTime(new Date());
        }
        return Result.content(drainReservePlanInfoService.saveOrUpdate(drainReservePlanInfo));
    }



    /**
     * 根据ID删除预案基础信息
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteReservePlanInfo")
    @Operation(summary = "根据ID删除预案基础信息", description = "根据ID删除预案基础信息")
    public Result deleteReservePlanInfo(@RequestBody List<String> ids) {
        return Result.content(drainReservePlanInfoService.deleteReservePlanInfoByIds(ids));
    }


    /**
     * 分页获取预案基础信息列表
     *
     * @param drainReservePlanInfoVo
     * @return
     */
    @PostMapping("/getReservePlanInfoList")
    @Operation(summary = "分页获取预案基础信息列表", description = "分页获取预案基础信息列表")
    @Parameters({
            @Parameter(required = false, name = "name", description = "预案名称"),
            @Parameter(required = false, name = "typeCode", description = "预案类别"),
            @Parameter(required = false, name = "cmStartPublishTime", description = "预案发布开始时间"),
            @Parameter(required = false, name = "cmEndPublishTime", description = "预案发布开始时间"),
            @Parameter(required = false, name = "status", description = "预案状态"),
            @Parameter(required = false, name = "current", description = "当前页码"),
            @Parameter(required = false, name = "size", description = "每页显示条数")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.RESERVE_PLAN_TYPE, targetField = "typeCode"),
    })
    public Result<IPage<DrainReservePlanInfo>> getReservePlanInfoList(@RequestBody DrainReservePlanInfoVo drainReservePlanInfoVo) {
        IPage<DrainReservePlanInfo> drainReservePlanInfoListByCondition = drainReservePlanInfoService.getReservePlanInfoList(drainReservePlanInfoVo);
        return Result.content(drainReservePlanInfoListByCondition);
    }


    /**
     * 导出预案基础信息
     * @param drainReservePlanInfoVo
     */
    @PostMapping("/exportReservePlanInfoFile")
    @Operation(summary = "导出预案基础信息", description = "导出预案基础信息")
    public void exportReservePlanInfoFile(@RequestBody DrainReservePlanInfoVo drainReservePlanInfoVo) {
        drainReservePlanInfoService.exportReservePlanInfoFile(httpServletResponse,drainReservePlanInfoVo);
    }


    /**
     * 获取预案详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getReservePlanInfo")
    @Operation(summary = "获取预案详情信息", description = "获取预案详情信息")
    @Parameters({
            @Parameter(required = true, name = "id", description = "预案id"),
    })
    public Result getReservePlanInfo(String id) {
        return Result.content(drainReservePlanInfoService.getReservePlanInfoById(id));
    }

}
